/*
 * 创建日期 2009-3-13
 *
 * 成都天和软件公司
 * 电话：028-85425861
 * 传真：028-85425861-8008
 * 邮编：610041 
 * 版权所有
 */
package  org.fantasy.common.grid.tag;

import  org.fantasy.common.grid.bean.ReportParam;
import  org.fantasy.common.grid.bean.ReportTagParam;
import  org.fantasy.common.grid.part.Part;
import  org.fantasy.common.grid.part.PartFactory;
import  org.fantasy.common.grid.report.ReportBuilder;
import  org.fantasy.common.grid.table.TableBuilderFactory;
import  org.fantasy.common.util.Debug;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *  表格标签
 * @author: 王文成
 * @version: 1.0
 * @since 2009-3-13
 */
public class GridTableTag extends AbstractReportTag{
    private final Log log = LogFactory.getLog(GridTableTag.class);
    
    @Override
    public void init() {
        super.init();
        getReportParam().setRowCustom(" org.fantasy.common.grid.custom.GridRowCustom");
    }

    @Override
    protected String getReportType() {
        return ReportTagParam.REPORT_TYPE_LIST;
    }
    
    public GridTableTag(){
        log.debug(">>>>>>>>>>>>>>>>>>> New GridTableTag instance!");
    }

    /**
     * 构造表格
     * 
     * @return
     */
    @Override
    protected String getReportHtml() throws Exception {
        Debug debug = new Debug("GridTable");
        debug.start("Building GridTable");
        ReportParam param = getReportParam();
        ReportBuilder builder = TableBuilderFactory.getGridTableBuilder(param);
        Part part = PartFactory.getGridTablePart(param,getRequest());
        StringBuffer html = new StringBuffer(1024);
        html.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + getCtx() + "/css/grid.css\">\n");
        html.append("<table id=\""
                        + param.getId()
                        + "\" style='" + param.getStyle() + ";table-layout:fixed;' cellspacing='0' cellpadding='0' border='0'> \n");
        html.append("<tr> \n");
        html.append("  <td> \n");
        html.append("   <div class='report'> \n");
        html.append(builder.getReport());
        html.append("   </div> \n");
        html.append("   </td> \n");
        html.append("</tr> \n");
        html.append(part.getPager());
        html.append("</table> \n");
        html.append(part.getScript());
        html.append(part.getParams());
        debug.end("Building GridTable");
        log.info(debug);
        return html.toString();
    }
}
